// VixsTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "VixsTest.h"
#include "VixsTestDlg.h"
#include "MVVSREC.h"
#include "COMMON.h"
#include "MVAPI.h"
#include "MVBOARD2.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BOOL m_bMosiacFlag;
DWORD m_RecFileSize = 0;
DWORD m_RecFileSize1 = 0;
BOOL m_OpenFlag[2];
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVixsTestDlg dialog

CVixsTestDlg::CVixsTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVixsTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVixsTestDlg)
	m_iWidth = 720;
	m_iHeight = 576;
	m_iVBitRate = 8000000;
	m_iFrate = 25;
	m_iVBitRate1 =8000000;
	m_iHeight1 = 576;
	m_iWidth1 = 720;
	m_iFrate1 = 25;
	m_TEXT1 = _T("");
	m_XPos1 = _T("");
	m_YPos1 = _T("");
	m_SpaceNum1 = _T("");
	m_bOSDText1 = FALSE;
	m_bOSDTime1 = FALSE;
	m_bOSDText2 = FALSE;
	m_bOSDTime2 = FALSE;
	m_TEXT2 = _T("");
	m_XPos2 = _T("");
	m_YPos2 = _T("");
	m_SpaceNum2 = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CVixsTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVixsTestDlg)
	DDX_Control(pDX, IDC_CMB_VF1, m_cBVideoFmt1);
	DDX_Control(pDX, IDC_CMB_VF, m_cBVideoFmt);
	DDX_Control(pDX, IDC_CMB_ENC1, m_iEncMode1);
	DDX_Control(pDX, IDC_CMB_ENC, m_iEncMode);
	DDX_Text(pDX, IDC_EDITWIDTH, m_iWidth);
	DDX_Text(pDX, IDC_EDITHEIGHT, m_iHeight);
	DDX_Text(pDX, IDC_EDITBITRATE, m_iVBitRate);
	DDX_Text(pDX, IDC_EDITFRATE, m_iFrate);
	DDX_Text(pDX, IDC_EDITBITRATE1, m_iVBitRate1);
	DDX_Text(pDX, IDC_EDITHEIGHT1, m_iHeight1);
	DDX_Text(pDX, IDC_EDITWIDTH1, m_iWidth1);
	DDX_Text(pDX, IDC_EDITFRATE1, m_iFrate1);
	DDX_Text(pDX, IDC_EDIT_TEXT1, m_TEXT1);
	DDX_Text(pDX, IDC_EDIT_XPOS1, m_XPos1);
	DDX_Text(pDX, IDC_EDIT_YPOS1, m_YPos1);
	DDX_Text(pDX, IDC_EDIT_SPACENUM1, m_SpaceNum1);
	DDX_Check(pDX, IDC_CHK_TEXT1, m_bOSDText1);
	DDX_Check(pDX, IDC_CHK_TIME1, m_bOSDTime1);
	DDX_Check(pDX, IDC_CHK_TEXT2, m_bOSDText2);
	DDX_Check(pDX, IDC_CHK_TIME2, m_bOSDTime2);
	DDX_Text(pDX, IDC_EDIT_TEXT2, m_TEXT2);
	DDX_Text(pDX, IDC_EDIT_XPOS2, m_XPos2);
	DDX_Text(pDX, IDC_EDIT_YPOS2, m_YPos2);
	DDX_Text(pDX, IDC_EDIT_SPACENUM2, m_SpaceNum2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CVixsTestDlg, CDialog)
	//{{AFX_MSG_MAP(CVixsTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
	ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
	ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
	ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
	ON_BN_CLICKED(IDC_CHK_TEXT1, OnChkText1)
	ON_BN_CLICKED(IDC_INITDEVICE, OnInitdevice)
	ON_BN_CLICKED(IDC_STARTCAP, OnStartcap)
	ON_BN_CLICKED(IDC_STOPCAP, OnStopcap)
	ON_BN_CLICKED(IDC_CLOSEDEVICE, OnClosedevice)
	ON_BN_CLICKED(IDC_CHK_TIME1, OnChkTime1)
	ON_BN_CLICKED(IDC_CHK_TEXT2, OnChkText2)
	ON_BN_CLICKED(IDC_CHK_TIME2, OnChkTime2)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVixsTestDlg message handlers

BOOL CVixsTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here


	m_iEncMode.SetCurSel(0);
	m_iEncMode1.SetCurSel(0);	
	m_cBVideoFmt.SetCurSel(1);
	m_cBVideoFmt1.SetCurSel(1);

	m_OpenFlag[0] = FALSE;
	m_OpenFlag[1] = FALSE;

	SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);
	char Buf[255];
	GetPrivateProfileString("OSD", "XPOS" ,"15", Buf,200, "MVOSD.ini");
	m_XPos1 = Buf;
	m_XPos2 = Buf;
	GetPrivateProfileString("OSD", "YPOS","5" , Buf,200, "MVOSD.ini");
	m_YPos1 = Buf;
	m_YPos2 = Buf;
	GetPrivateProfileString("OSD", "TEXT" ,"MICROVIEW", Buf,200, "MVOSD.ini");
	m_TEXT1 = Buf;
	m_TEXT2 = Buf;
	GetPrivateProfileString("OSD", "SPACENUM", "0", Buf,200 , "MVOSD.ini");
	m_SpaceNum1 = Buf;
	m_SpaceNum2 = Buf;


	
	UpdateData(FALSE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CVixsTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CVixsTestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CVixsTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CVixsTestDlg::OnButton1() 
{
	BOOL  bl = MVV_OpenDevice(0);
	if(bl == FALSE)
	{
		AfxMessageBox("打开压缩设备失败 !");
	}
	else
	{
		m_OpenFlag[0] = TRUE;
		GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON4)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON6)->EnableWindow(TRUE);
	}

	WritePrivateProfileString("OSD", "XPOS" , m_XPos1, "MVOSD.ini");
	WritePrivateProfileString("OSD", "YPOS" , m_YPos1, "MVOSD.ini");
	
	if(!m_bOSDText1 && !m_bOSDTime1)
	{
		
		WritePrivateProfileString("OSD", "TEXT" , "", "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum1 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_DISABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_DISABLE, TRUE);

	}
	else if(!m_bOSDText1 && m_bOSDTime1)
	{
		
		WritePrivateProfileString("OSD", "TEXT" , "", "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum1 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, FALSE);
	}
	else if(!m_bOSDTime1&&m_bOSDText1 )
	{
		
		WritePrivateProfileString("OSD", "TEXT" , m_TEXT1, "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum1 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
	}	
	else if(m_bOSDTime1&&m_bOSDText1 )
	{
		
		WritePrivateProfileString("OSD", "TEXT" , m_TEXT1, "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum1 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
	}
}

UINT StreamProc(DWORD wHWCardNo,LPBYTE lpBuffer, DWORD DataLenth, PVOID pUserData)
{
	CVixsTestDlg*    ptDlg = (CVixsTestDlg*)pUserData;
	char DDBuf[255];
	m_RecFileSize = m_RecFileSize + DataLenth;
	sprintf(DDBuf,"NO:%d 录像文件大小 ：%d",wHWCardNo,m_RecFileSize);
	ptDlg->GetDlgItem(IDC_RECSIZE)->SetWindowText(DDBuf);
	return 0;
}

void CVixsTestDlg::OnButton2() 
{

	SetTimer(0,180000,NULL);
	if(m_OpenFlag[0] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	
	SYSTEMTIME lpSystemTime;
	char     DatString[255];
	GetLocalTime( &lpSystemTime ); 
	sprintf(DatString,"C:\\%4d%02d%02d%02d%02d%02d_0",lpSystemTime.wYear,lpSystemTime.wMonth,lpSystemTime.wDay,lpSystemTime.wHour,lpSystemTime.wMinute,lpSystemTime.wSecond);
	MVV_SetRecFileName(0,DatString);

	UpdateData(TRUE);
	m_RecFileSize = 0;
	MVV_RecStreamHook(0,StreamProc,this);
	ENCODE_PARAM m_Param;

    //设置编码方式，其中固定码流为MPEG2_CBR和MPEG4_CBR
	//0=MPEG2_PS 1=MP4_MSV 2=MP4_GEN 3=MP4_PSP 4=MPEG2_VBR 5=MPEG2_CBR 6=MPEG4_VBR 7=MPEG4_CBR
	m_Param.ENC_Type = m_iEncMode.GetCurSel(); 
	m_Param.VideoFormat = m_cBVideoFmt.GetCurSel();//PAL NTSC
	m_Param.Width = m_iWidth;    
	m_Param.Height = m_iHeight;
	m_Param.VF_Rate = m_iFrate;   // MPEG2(NTSC:30fps PAL:25fps) MPEG4(NTSC:30fps/15fps/10fps PAL:25fps/12fps/8fps)
	m_Param.VBitRate = m_iVBitRate;
	MVV_StartRecode(0,m_Param);	

	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
}

void CVixsTestDlg::OnButton12() 
{
	if(m_OpenFlag[0] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	MVV_PauseRecode(0);	
}

void CVixsTestDlg::OnButton3() 
{
	if(m_OpenFlag[0] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	MVV_StopRecode(0);	
	GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);

}

void CVixsTestDlg::OnButton4() 
{
	if(m_OpenFlag[0] == TRUE)
	{
		MVV_CloseDevice(0);
		m_OpenFlag[0] = FALSE;
		GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON6)->EnableWindow(FALSE);
	}
}

void CVixsTestDlg::OnButton5() 
{

}

void CVixsTestDlg::OnButton6() 
{
	if(m_OpenFlag[0] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	UpdateData(TRUE);

	MVV_UpdateParameters(0,m_iVBitRate);	
}

void CVixsTestDlg::OnButton7() 
{
	BOOL  bl = MVV_OpenDevice(1);
	if(bl == FALSE)
	{
		AfxMessageBox("打开压缩设备失败 !");
	}
	else
	{
		m_OpenFlag[1] = TRUE;
		GetDlgItem(IDC_BUTTON7)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON8)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON9)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON10)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON14)->EnableWindow(TRUE);
	}
	WritePrivateProfileString("OSD", "XPOS" , m_XPos2, "MVOSD.ini");
	WritePrivateProfileString("OSD", "YPOS" , m_YPos2, "MVOSD.ini");
	
	if(!m_bOSDText2 && !m_bOSDTime2)
	{
		
		WritePrivateProfileString("OSD", "TEXT" , "", "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum2 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_DISABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_DISABLE, TRUE);

	}
	else if(!m_bOSDText2 && m_bOSDTime2)
	{
		
		WritePrivateProfileString("OSD", "TEXT" , "", "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum2, "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, FALSE);
	}
	else if(!m_bOSDTime2&&m_bOSDText2 )
	{
		
		WritePrivateProfileString("OSD", "TEXT" , m_TEXT2, "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum2 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
	}	
	else if(m_bOSDTime2&&m_bOSDText2)
	{
		
		WritePrivateProfileString("OSD", "TEXT" , m_TEXT2, "MVOSD.ini");
	    WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum2 , "MVOSD.ini");

		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
	}	
}

UINT StreamProc1(DWORD wHWCardNo,LPBYTE lpBuffer, DWORD DataLenth, PVOID pUserData)
{
	CVixsTestDlg*    ptDlg = (CVixsTestDlg*)pUserData;
	char DDBuf[255];
	m_RecFileSize1 = m_RecFileSize1 + DataLenth;
	sprintf(DDBuf,"NO:%d 录像文件大小 ：%d",wHWCardNo,m_RecFileSize1);
	ptDlg->GetDlgItem(IDC_RECSIZE2)->SetWindowText(DDBuf);
	return 0;
}

void CVixsTestDlg::OnButton8() 
{
	if(m_OpenFlag[1] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}

	SYSTEMTIME lpSystemTime;
	char     DatString[255];
	GetLocalTime( &lpSystemTime ); 
	sprintf(DatString,"C:\\%4d%02d%02d%02d%02d%02d_1",lpSystemTime.wYear,lpSystemTime.wMonth,lpSystemTime.wDay,lpSystemTime.wHour,lpSystemTime.wMinute,lpSystemTime.wSecond);
	MVV_SetRecFileName(1,DatString);

	m_RecFileSize1 = 0;
	MVV_RecStreamHook(1,StreamProc1,this);
	ENCODE_PARAM m_Param1;
	
    //设置编码方式，其中固定码流为MPEG2_CBR和MPEG4_CBR
	//0=MPEG2_PS 1=MP4_MSV 2=MP4_GEN 3=MP4_PSP 4=MPEG2_VBR 5=MPEG2_CBR 6=MPEG4_VBR 7=MPEG4_CBR
	m_Param1.ENC_Type = m_iEncMode1.GetCurSel(); 
	m_Param1.VideoFormat = m_cBVideoFmt1.GetCurSel();//PAL = 0 NTSC = 1
	m_Param1.Width = m_iWidth1;// 720;    
	m_Param1.Height = m_iHeight1;//576;
	m_Param1.VF_Rate = m_iFrate1;//25;   // MPEG2(NTSC:30fps PAL:25fps) MPEG4(NTSC:30fps/15fps/10fps PAL:25fps/12fps/8fps)
	m_Param1.VBitRate = m_iVBitRate1;//8000000;
	MVV_StartRecode(1,m_Param1);	
	GetDlgItem(IDC_BUTTON8)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON9)->EnableWindow(TRUE);
}

void CVixsTestDlg::OnButton9() 
{
	if(m_OpenFlag[1] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	MVV_StopRecode(1);
		GetDlgItem(IDC_BUTTON8)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON9)->EnableWindow(FALSE);
}

void CVixsTestDlg::OnButton10() 
{
	if(m_OpenFlag[1] == TRUE)
	{
		MVV_CloseDevice(1);
		m_OpenFlag[1] = FALSE;
		GetDlgItem(IDC_BUTTON7)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON8)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON9)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON10)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON14)->EnableWindow(FALSE);
	}
}


void CVixsTestDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

BOOL CVixsTestDlg::DestroyWindow() 
{
	if(m_OpenFlag[0] == TRUE)
	{
		MVV_StopRecode(0);
		MVV_CloseDevice(0);
	}
	if(m_OpenFlag[1] == TRUE)
	{
		MVV_StopRecode(1);
		MVV_CloseDevice(1);
	}	
	return CDialog::DestroyWindow();
}

void CVixsTestDlg::OnButton14() 
{
	if(m_OpenFlag[1] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	UpdateData(TRUE);

	MVV_UpdateParameters(1,m_iVBitRate);	
}

void CVixsTestDlg::OnButton15() 
{
	if(m_OpenFlag[1] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	MVV_PauseRecode(1);	
	
}


void CVixsTestDlg::OnInitdevice() 
{
	nBdNum = MV_GetDeviceNumber();

	if(nBdNum<=0)
	{
		MessageBox("未找到设备,请检查板卡驱动安装是否正确!","错误!",MB_OK);
	}
	if(nBdNum>2)
	{
		nBdNum=2;
	}

	for(DWORD i=0;i<nBdNum;i++)
	{
	    CurDevice[i] = MV_OpenDevice( i, TRUE );
        Val=MV_GetDeviceParameter(CurDevice[i],GET_BOARD_TYPE);
		if(Val==S260)
		   AfxMessageBox("当前卡是S260硬压卡,支持硬压功能! ");
        else if(Val==MOKAM20)
		   AfxMessageBox("当前卡是Moka-M20硬压卡,支持硬压功能! ");
		else 
		   AfxMessageBox("当前卡不支持硬压功能! ");
			

	}

}

void CVixsTestDlg::OnStartcap() 
{
	CRect rect1,rect2;

	hwnd[0]=GetSafeHwnd();
	hwnd[1]=GetSafeHwnd();
	hwnd[0]=GetDlgItem(IDC_STATIC_PIC1)->GetSafeHwnd();
	hwnd[1]=GetDlgItem(IDC_STATIC_PIC2)->GetSafeHwnd();
	GetDlgItem(IDC_STATIC_PIC1)->GetClientRect(&rect1);
	GetDlgItem(IDC_STATIC_PIC2)->GetClientRect(&rect2);

//	RECT rect[2];
//	GetDlgItem(IDC_STATIC_PIC1)->GetWindowRect(rect[0]);
//	GetDlgItem(IDC_STATIC_PIC2)->GetWindowRect(rect[1]);

	for(DWORD i=0;i<nBdNum;i++)
	{
		MV_SetDeviceParameter( CurDevice[i], GARB_IN_WIDTH, 768);
		MV_SetDeviceParameter( CurDevice[i], GARB_IN_HEIGHT, 288);
		MV_SetDeviceParameter( CurDevice[i], GARB_WIDTH, 768);
		MV_SetDeviceParameter( CurDevice[i], GARB_HEIGHT, 288);
		MV_SetDeviceParameter( CurDevice[i], GARB_BITDESCRIBE, DATA_RGB1555);
		MV_SetDeviceParameter( CurDevice[i], DISP_WHND, (DWORD)hwnd[i]);
		MV_SetDeviceParameter( CurDevice[i], DISP_HEIGHT, rect1.bottom-rect1.top );
		MV_SetDeviceParameter( CurDevice[i], DISP_WIDTH, rect1.right-rect1.left);
		MV_SetDeviceParameter( CurDevice[i], DISP_PRESENCE, 1);
		MV_OperateDevice( CurDevice[i], MVRUN );	

	}
}

void CVixsTestDlg::OnStopcap() 
{
	for(DWORD i=0;i<nBdNum;i++)
	{
	    MV_OperateDevice( CurDevice[i], MVSTOP );
	}
}

void CVixsTestDlg::OnClosedevice() 
{
	for(DWORD i=0;i<nBdNum;i++)
	{
		MV_CloseDevice( CurDevice[i]);	
	}
}
void CVixsTestDlg::OnChkText1() 
{
 	UpdateData(TRUE);

	WritePrivateProfileString("OSD", "XPOS" , m_XPos1, "MVOSD.ini");
	WritePrivateProfileString("OSD", "YPOS" , m_YPos1, "MVOSD.ini");

	WritePrivateProfileString("OSD", "TEXT" , m_TEXT1, "MVOSD.ini");
	WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum1 , "MVOSD.ini");

	MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_DISABLE, TRUE);
	MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_DISABLE, TRUE);
	if(m_bOSDText1 && !m_bOSDTime1)
	{
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDText1 && m_bOSDTime1)
	{
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDTime1&&!m_bOSDText1 )
	{
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, FALSE);
	}

}

void CVixsTestDlg::OnChkTime1() 
{
	UpdateData(TRUE);
	WritePrivateProfileString("OSD", "XPOS" , m_XPos1, "MVOSD.ini");
	WritePrivateProfileString("OSD", "YPOS" , m_YPos1, "MVOSD.ini");
	MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_DISABLE, TRUE);
	MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_DISABLE, TRUE);
	
	if(m_bOSDTime1&&!m_bOSDText1 )
	{
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, FALSE);

	}
	else if(m_bOSDTime1 && m_bOSDText1 )
	{
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDText1 && !m_bOSDTime1)
	{
		MV_SetDeviceParameter( CurDevice[0], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[0], REC_OSDADDTEXT, TRUE);
	}

}

void CVixsTestDlg::OnChkText2() 
{
	UpdateData(TRUE);

	WritePrivateProfileString("OSD", "XPOS" , m_XPos2, "MVOSD.ini");
	WritePrivateProfileString("OSD", "YPOS" , m_YPos2, "MVOSD.ini");

	WritePrivateProfileString("OSD", "TEXT" , m_TEXT2, "MVOSD.ini");
	WritePrivateProfileString("OSD", "SPACENUM" , m_SpaceNum2 , "MVOSD.ini");

	MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_DISABLE, TRUE);
	MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_DISABLE, TRUE);

	if(m_bOSDText2 && !m_bOSDTime2)
	{
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDText2 && m_bOSDTime2)
	{
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDTime2&&!m_bOSDText2 )
	{
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, FALSE);

	}

}

void CVixsTestDlg::OnChkTime2() 
{
	UpdateData(TRUE);
	WritePrivateProfileString("OSD", "XPOS" , m_XPos2, "MVOSD.ini");
	WritePrivateProfileString("OSD", "YPOS" , m_YPos2, "MVOSD.ini");

	MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_DISABLE, TRUE);
	MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_DISABLE, TRUE);
	
	if(m_bOSDText2 && !m_bOSDTime2)
	{
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDText2 && m_bOSDTime2)
	{
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, TRUE);
	}
	else if(m_bOSDTime2&&!m_bOSDText2)
	{
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTIME_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDTEXT_ENABLE, TRUE);
		MV_SetDeviceParameter( CurDevice[1], REC_OSDADDTEXT, FALSE);

	}
}

void CVixsTestDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_OpenFlag[0] == FALSE){ AfxMessageBox("压缩设备还没有打开 ! "); return;}
	MVV_StopRecode(0);	
	GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);

	
	CDialog::OnTimer(nIDEvent);
}
